<template>
  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-if="open" v-model="open" width="1200px" append-to-body>
    <selectMaterialForm ref="selectMaterialForm"></selectMaterialForm>
    <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="true">
      <el-form-item label="客户:" prop="categoryName">
        <el-input v-model="queryParams.categoryName" placeholder="请选择客户"></el-input>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" style="width: 100%" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="报价单号:" prop="categoryName">
        <el-input v-model="queryParams.categoryName" placeholder="自动生成"></el-input>
      </el-form-item>
      <el-form-item label="方案:" prop="categoryName">
        <el-input v-model="queryParams.categoryName" placeholder="请选择方案"></el-input>
      </el-form-item>
      <el-form-item label="适用价格:" prop="categoryName">
        <el-input v-model="queryParams.categoryName" placeholder="自动跟出"></el-input>
      </el-form-item>
      <el-form-item label="联系人:" prop="categoryName">
        <el-input v-model="queryParams.categoryName" placeholder="请选择联系人"></el-input>
      </el-form-item>
      <el-form-item label="单据备注:" prop="sort">
        <el-input style="width: 200%" :rows="4" v-model="queryParams.sort"></el-input>
      </el-form-item>
    </el-form>

    <el-card class="box-card" shadow="always">
      <div slot="header" style="
          display: flex;
          align-items: center;
          justify-content: space-between;
        ">
        <span>选择商品</span>
        <el-button style="float: right" type="primary" @click="handleAdd">添加商品</el-button>
      </div>
      <el-table v-loading="loading" :data="dataSource" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" :selectable="selectHandle" />
        <el-table-column label="#" type="index"> </el-table-column>
        <el-table-column label="主图" align="center" prop="warehouseName" />
        <el-table-column label="商品名称" align="center" prop="warehouseName" width="150" />
        <el-table-column label="商品品牌" align="center" prop="warehouseName" />
        <el-table-column label="集采成本价" align="center" prop="warehouseName" />
        <el-table-column label="批发价" align="center" prop="warehouseName" />
        <el-table-column label="操作" align="center" prop="orderStatus">
          <template #default="scope"> </template>
        </el-table-column>
      </el-table>
    </el-card>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import selectMaterialForm from "./selectMaterialForm.vue";
export default {
  name: "addForm",
  components: {
    selectMaterialForm,
  },
  data() {
    return {
      open: false,
      title: "添加报价单",
      form: {
        categoryId: "",
        categoryName: "",
      },
      rules: {
        categoryId: [
          {
            required: true,
            message: "Please select a category",
            trigger: "change",
          },
        ],
        categoryName: [
          {
            required: true,
            message: "Please enter a category name",
            trigger: "blur",
          },
        ],
      },
      queryParams: {
        categoryId: "",
        categoryName: "",
      },
      active: 1,
      baseInput: 200,
      data: [],
      dateRange: [],
      dataSource: [],
      loading: false,
    };
  },
  methods: {
    add() {
      this.open = true;
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // Perform form submission logic here
        } else {
          // Handle form validation errors
        }
      });
    },
    cancel() {
      this.open = false;
    },
    categoryChange(value) {
      this.form.categoryId = value;
    },
    handleSelectionChange(val) {
      this.multiple = val.length > 1;
    },
    selectHandle(row) {
      return row.orderStatus === 1;
    },
    handleAdd() {
      this.$refs.selectMaterialForm.show();
    },
  },
};
</script>

<style lang="scss" scoped></style>